<?php
// DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
//header items
$jQuery = true;
$tinyMCE = true;
$jQueryCookie = true;
$hoverIntent = true;
//end header items
require_once ('../../config/include_paths.php');
require_once('config.php');
$pageTitle = SITE_NAME.' - Administration - Dashboard'; //must be set after the config.php include and before head.php include
require_once('dbconnect.php');	// database connect script.
session_start();

if ($_SESSION['logged_in'] == 0) {
	require ('security_check.php');
} else {
/* get all meeting info for use group query main query for page*/
/* GROUPS group query main query for page*/
$group_sql = "SELECT * FROM groups  ORDER BY groupname ASC";
$group_result = mysql_query($group_sql) or die(mysql_error());
$group_total = mysql_num_rows($group_result);	

$meeting_sql = "SELECT meetings.id
				FROM meetings,groups,locations,meeting_types 
				WHERE group_id=groups.id and location_id=locations.id and mtg_type_id=meeting_types.id";
$meeting_result = mysql_query($meeting_sql) or die(mysql_error());
$meeting_total  = mysql_num_rows($meeting_result);

$loc_sql = "SELECT * FROM locations  ORDER BY name ASC";
$loc_result = mysql_query($loc_sql) or die(mysql_error());
$loc_total = mysql_num_rows($loc_result);
require_once ('adminhead.php');
?>
<body onLoad="checkMenuSettings();">
<div id="wrapper">
  <?php require_once ('adminHeader.php'); ?>
  <div class="clearfloat">&nbsp;</div>
  <div id="sidebar">
    <?php require_once ('adminNav.php'); ?>
  </div>
  <div id="main_content">
    <div id="meetingTable">
      <table summary="" cellpadding="0" cellspacing="0" width="682px" height="100%">
        <thead class="fixedHeader">
          <tr bgcolor="#224995" style="width:100%">
            <th colspan="2"><h3>Meetings&nbsp;&nbsp;&nbsp;(<?php echo $meeting_total?>)</h3></th>
          </tr>
          <tr bgcolor="#224995" style="width:100%>
          	<td style="padding-left:3px; width:263px;">Field</td>
            <td style=" width:275px;">Item</td>
            <td  style="padding-right:25px; width:45px;">Count</td>
          </tr>
        </thead>
        <tbody>
<?php
$i = 0;
$meeting_fields = array('Day', 'City', 'Code', 'Open_Closed', 'Men_Women', 'HC');
foreach ($meeting_fields as $value) {
	
    $sql = "SELECT $value, count(*) as total
  			FROM meetings,groups,locations,meeting_types
 			WHERE group_id=groups.id and location_id=locations.id and mtg_type_id=meeting_types.id GROUP BY $value LIMIT 0, 30 ";
	$result = mysql_query($sql) or die(mysql_error());
		while ($row = mysql_fetch_assoc($result))
		{
			$field = $value;
			if ($value == 'Day') {
				$item = getDay($row['Day']); 
			}else{
				$item = $row[$value];
			}
			// set row color		
			if ($i%2 == 0) 
				{
					$rowcolor="$reprowcolor";
				} else {
					$rowcolor="white";
				}
			?>
          <tr bgcolor="<?php echo $rowcolor?>">
          	<td style="padding-left:3px; width:263px;"><?php echo $field;?></td>
            <td style="padding-left:3px; width:275px;"><?php echo $item;?></td>
            <td style="padding-left:3px; width:45px; text-align:right;"><?php echo $row['total'];?></td>
          </tr>
          <?php $i++;
	 	} 
	
	}?>
        </tbody>
      </table>
    </div>
  </div>
</div>
<?php mysql_close($conn);
} ?>
</body>
</html>